package com.roger.bt.trans.ser.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Logger {
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS", Locale.CHINA);

    @SuppressWarnings("ResultOfMethodCallIgnored")
    public static void log(String file,String content){
        String time = dateFormat.format(new Date(System.currentTimeMillis()));
        try {
            String s = time+": "+ content +"\n";
            File f = new File(file);
            if(!f.getParentFile().exists()) f.getParentFile().mkdirs();
            if(!f.exists()) f.createNewFile();
            FileWriter fw = new FileWriter(f,true);
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(s);
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
